from django.db import models
from datetime import datetime


# Create your models here.
class Platefrom(models.Model):
    """
    分发平台
    """
    name = models.CharField(max_length=100, verbose_name='名称')
    icon = models.CharField(verbose_name='图标',max_length=255,default='', blank=True, null=True)
    en_name = models.CharField(max_length=100, null=True, blank=True, verbose_name='英文名称')
    introduce = models.CharField(max_length=200, blank=True, null=True, verbose_name='简介')
    request_url = models.CharField(max_length=200, blank=True, null=True, verbose_name='请求URL')
    is_activate = models.IntegerField(choices=((0, '不可用'), (1, '可用')), default=1, verbose_name='平台是否可用')
    support_type = models.CharField(max_length=200, blank=True, null=True, verbose_name='支持类型')
    image_id = models.CharField(max_length=11, default='', null=True, verbose_name='关联imageId')

    class Meta:
        verbose_name_plural = '分发平台管理'

    def __str__(self):
        return self.name



class Skus(models.Model):
    """套餐"""
    title = models.CharField(max_length=32, verbose_name='规格标题')
    labels = models.CharField(verbose_name='规格标签', max_length=256, blank=True, null=True)
    order = models.IntegerField(verbose_name='规格排序', default=50)
    status = models.BooleanField(verbose_name="规格状态", default=True)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now, blank=True, null=True)
    platefrom_ids = models.CharField(verbose_name='支持平台', max_length=256, blank=True, null=True)
    content_type_ids = models.CharField(verbose_name='支持内容', max_length=256, blank=True, null=True)
    limit_count = models.IntegerField(verbose_name='限制条数', default=0)
    price = models.IntegerField(verbose_name='规格价格', default=0)
    item_price = models.CharField(max_length=10, verbose_name='规格价格', default='')
    discount = models.CharField(max_length=10,verbose_name='折扣率', default='')


    class Meta:
        verbose_name_plural = '平台套餐'

    def __str__(self):
        return self.title



class SkusUser(models.Model):
    """规格与分发用户中间表"""
    skus_id = models.CharField(max_length=256, verbose_name='规格',default='')
    user_id = models.CharField(max_length=256, verbose_name='分发用户',default='',blank=True)
    username = models.CharField(max_length=256, verbose_name='冗余用户名',default='',blank=True)
    company_id = models.CharField(max_length=256, verbose_name='公司',default='',blank=True)
    type = models.SmallIntegerField(verbose_name='类型，0：普通用户，1：公司用户',default=0)
    company_name = models.CharField(max_length=256, verbose_name='冗余公司名称',default='',blank=True)
    title = models.CharField(max_length=256, verbose_name='冗余sku标题',default='')
    add_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    balance_times = models.IntegerField(verbose_name='剩余次数',default=0)

    class Meta:
        verbose_name = '规格-分发用户'
        verbose_name_plural = verbose_name